package com.meituan.meituanservice.mapper;

import com.meituan.meituanservice.model.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    @Insert("insert into users(nick,password,phone,register_time) values(#{nick},#{password},#{phone},#{registerTime})")
    int add(User user);

    @Select("select * from users where user_id = #{id}")
    User selectById(Integer id);

    @Select("select * from users where nick = #{nick}")
    User selectByNick(String nick);

    @Select("select * from users where nick=#{nick} and password=#{password}")
    User selectByNickPassword(String nick,String password);

    @Update(("update users set phone=#{newPhone} where user_id=#{userId}"))
    int updatePhone(@Param("userId") Integer userId,@Param("newPhone") String newPhone);

    @Update(("update users set pay_code=#{newPayCode} where user_id=#{userId}"))
    int updatePayCode(@Param("userId") Integer userId,@Param("newPayCode") String newPayCode);

    @Update("update users set avatar=#{path} where user_id=#{userId}")
    int updateAvatar(@Param("path") String path,@Param("userId")String userId);

    @Select("select pay_code from users where user_id=#{userId}")
    String selectPayCodeById(String userId);

}
